import axios from 'axios';
import router from '@/router';
import store from '@/store';
import { Notification, MessageBox } from 'element-ui';
import { serialize } from '@/utils/tools';
import { getToken, setToken } from '@/utils/auth';
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css';
const noToken = ['/login'];

// create an axios instance
const service = axios.create({
    // baseURL: process.env.VUE_APP_BASE_API, // url
    // withCredentials: true, // send cookies when cross-domain requests
    timeout: 15 * 1000, // request timeout 15s
    validateStatus: status => status >= 200 && status <= 500 // 默认的
});
// NProgress Configuration
NProgress.configure({
    showSpinner: false
});
// request interceptor
service.interceptors.request.use(
    config => {
        NProgress.start(); // start progress bar
        config.baseURL = getToken('api_domain') ? getToken('api_domain') : '';
        config.headers['Auth-Key'] = getToken('auth_key') ? getToken('auth_key') : '';
        config.headers['Session-Id'] = getToken('session_id') ? getToken('session_id') : '';
        config.headers['Platform'] = 'pc';
        // headers中配置serialize为true开启序列化
        if (config.method === 'post' && config.headers.serialize) {
            config.data = serialize(config.data);
            delete config.data.serialize;
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);

export const getBasicInfo = () => {
    return axios.get(process.env.VUE_APP_BASE_API + '/admin/base/getBusinessInfo', {
        params: {
            url: location.origin
                // url: 'http://173.16.200.25:4001'
        },
        headers: {
            'Platform': 'pc'
        }
    });
};
export default service;
